<?php
require_once 'MyPDO.php';
require_once 'PreparationREQ.php';

try {

$db = new MyPDO('mysql:host=localhost;dbname=tp3-diaz','root','');
echo "Connexion reussie\n\n";


$PrepREQ = new PreparationREQ($db);

//affichage des donnees avant modification
print_r($PrepREQ->selectAll());

//RECUP donnÃ©es formulaire

	if (isset ($_POST['name'])&&($_POST['departement'])&&($_POST['password'])){
	
	if (!empty($_POST['name'])&&($_POST['departement'])&&($_POST['password']))
	{
		$name = $_POST['name'];
		$departement = $_POST['departement'];
		$password = $_POST['password'];
		$PrepREQ->insert("$name", $password, $departement);
	}
	
	}


	//affichage en brut des donnÃ©es issues de la BD grÃ¢ce au print_r (echo Ã©voluÃ©)
	print_r($PrepREQ->selectById(1));
	print_r($PrepREQ->selectByName('u'));

	try 
	{
		$AllRows = $PreparationREQ->selectAll();
		foreach ($AllRows as $OneRow){
			echo ($OneRow['name'] . "-" . $OneRow['password'] . "</br>");
		}
		
	}catch (Exception $e) {
	die("Impossible de se connecter: " . $e->getMessage());
	}

}
catch (PDOException $e)
{
	print $e->getMessage();
}


?>